// index.js
const { getbanner,getGoods } = require("../api/index")
Page({
  data: {
    value:"",
    swiperOptions:{
      indicatorDots:true,
      autoplay:true,
      interval:3000,
      dureation:1000,
      swiperData:[]
    },
    navData:[
      {
          text:"数码",
          icon:"like",
          color:"#ff0000"
      },
      {
          text:"生鲜",
          icon:"star",
          color:"#ff0000"
      },
      {
          text:"会员",
          icon:"fire",
          color:"#ff0000"
      },
      {
          text:"优惠",
          icon:"gift",
          color:"#ff0000"
      },
      {
          text:"充值",
          icon:"phone",
          color:"#ff0000"
      },
      {
          text:"领券",
          icon:"gem",
          color:"#ff0000"
      },
      {
          text:"外卖",
          icon:"gift-card",
          color:"#ff0000"
      },
      {
          text:"美食",
          icon:"smile",
          color:"#ff0000"
      }
  ],
  page:1,
  goodsData:[]

    },
    onLoad(){
      getbanner().then(res =>{
        if(res.data.status === 200){
          this.setData({
            swiperOptions:{
              indicatorDots:true,
              autoplay:true,
              interval:3000,
              dureation:1000,
              swiperData:res.data.data.result
            }
          })
        }
        // console.log(res)
      })
      this.http(this.data.page)
    },
    http(page){
      getGoods({page}).then(res =>{
        if(!res.data.msg){
          this.setData({
            goodsData:this.data.goodsData.concat(res.data.data.result)
          })
          // console.log(res.data.data.result)
        }else{
          wx.showToast({
            title:res.data.msg,
            icon:"success",
            duration:2000
          })
        }
        // console.log(res)
      })
    },
    onReachBottom(){
      //更改页码
      this.setData({
        page:this.data.page += 1
      })
      // console.log(this.data.page)
      this.http(this.data.page)
    },
    clickSearch(){
      wx.navigateTo({
        url: '/pages/search/search',
      })
    }
  
})
